
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4.3 ingress · Kubernetes - 痴者工良</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="痴者工良">
        
        
    
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.discovery.html" />
    
    
    <link rel="prev" href="2.endpoint.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.whuanle.cn" target="_blank" class="custom-link">痴者工良的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    文档说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../1.basic/">
            
                <a href="../1.basic/">
            
                    
                    1.基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../1.basic/">
            
                <a href="../1.basic/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../1.basic/1.docker.html">
            
                <a href="../1.basic/1.docker.html">
            
                    
                    1.1 说透 Docker：基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../1.basic/2.virtual.html">
            
                <a href="../1.basic/2.virtual.html">
            
                    
                    1.2 说透 Docker： 虚拟化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../1.basic/3.docker_network.html">
            
                <a href="../1.basic/3.docker_network.html">
            
                    
                    1.3 了解 Docker 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../1.basic/4.pod_docker.html">
            
                <a href="../1.basic/4.pod_docker.html">
            
                    
                    1.4 Docker 和 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../1.basic/5.k8s.html">
            
                <a href="../1.basic/5.k8s.html">
            
                    
                    1.5 K8S入门基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../2.deploy/">
            
                <a href="../2.deploy/">
            
                    
                    2.部署和配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../2.deploy/2.deploy.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../2.deploy/1.minikube.html">
            
                <a href="../2.deploy/1.minikube.html">
            
                    
                    2.1 使用 Minikube 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../2.deploy/2.kubeadm.html">
            
                <a href="../2.deploy/2.kubeadm.html">
            
                    
                    2.2 使用 kubeadm 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../2.deploy/3.kubeadm_ckad.html">
            
                <a href="../2.deploy/3.kubeadm_ckad.html">
            
                    
                    2.3 CKAD认证中的部署教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../2.deploy/4.kubeadm_proxy.html">
            
                <a href="../2.deploy/4.kubeadm_proxy.html">
            
                    
                    2.4 国内代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../2.deploy/5.dashboard.html">
            
                <a href="../2.deploy/5.dashboard.html">
            
                    
                    2.5 Dashboard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    3.Pod部署和调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../3.pod/1.pod.html">
            
                <a href="../3.pod/1.pod.html">
            
                    
                    3.1 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../3.pod/2.deployment.html">
            
                <a href="../3.pod/2.deployment.html">
            
                    
                    3.2 Deployment部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../3.pod/3.replica.html">
            
                <a href="../3.pod/3.replica.html">
            
                    
                    3.3 副本集(ReplicaSet)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../3.pod/4.pod_network.html">
            
                <a href="../3.pod/4.pod_network.html">
            
                    
                    3.34 Pod 端口映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../3.pod/5.update.html">
            
                <a href="../3.pod/5.update.html">
            
                    
                    3.5 Pod 升级、回滚
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../3.pod/6.scale.html">
            
                <a href="../3.pod/6.scale.html">
            
                    
                    3.6 Pod 缩放
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../3.pod/7.lable.html">
            
                <a href="../3.pod/7.lable.html">
            
                    
                    3.7.Pod 标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../3.pod/8.schedule.html">
            
                <a href="../3.pod/8.schedule.html">
            
                    
                    3.8 Pod 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../3.pod/9.jobs_cronjobs.html">
            
                <a href="../3.pod/9.jobs_cronjobs.html">
            
                    
                    3.9 Jobs、CronJobs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    4.Kubernetes 网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="./">
            
                <a href="./">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="1.network.html">
            
                <a href="1.network.html">
            
                    
                    4.1 Kubernetes 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="2.endpoint.html">
            
                <a href="2.endpoint.html">
            
                    
                    4.2 Endpoint
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="3.ingress.html">
            
                <a href="3.ingress.html">
            
                    
                    4.3 ingress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="4.discovery.html">
            
                <a href="4.discovery.html">
            
                    
                    4.4 服务发现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    5.volumes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../5.volumes/1.volumes.html">
            
                <a href="../5.volumes/1.volumes.html">
            
                    
                    5.1 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../5.volumes/2.secret_configmap.html">
            
                <a href="../5.volumes/2.secret_configmap.html">
            
                    
                    5.2 secret 和 ConfigMap 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../5.volumes/3.nfts.html">
            
                <a href="../5.volumes/3.nfts.html">
            
                    
                    5.3 NFS卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../5.volumes/4.pv_pvc.html">
            
                <a href="../5.volumes/4.pv_pvc.html">
            
                    
                    5.4 持久化卷
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    6.API 和 安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../7.health/">
            
                <a href="../7.health/">
            
                    
                    7.维护和故障排除
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../8.health/README.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../k8s.html">
            
                <a href="../k8s.html">
            
                    
                    Kubernetes 命令概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../ckad.html">
            
                <a href="../ckad.html">
            
                    
                    CKAD 认证帮助
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >4.3 ingress</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#43-ingress"><b></b>4.3 ingress</a></li><ul><li><span class="title-icon "></span><a href="#&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;"><b></b>&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4EC0;&#x4E48;&#x662F;-ingress"><b></b>&#x4EC0;&#x4E48;&#x662F; Ingress</a></li><li><span class="title-icon "></span><a href="#ingress-&#x4E0E;-service"><b></b>Ingress &#x4E0E; Service</a></li></ul><li><span class="title-icon "></span><a href="#&#x5B89;&#x88C5;-ingress-&#x63A7;&#x5236;&#x5668;"><b></b>&#x5B89;&#x88C5; Ingress &#x63A7;&#x5236;&#x5668;</a></li><ul><li><span class="title-icon "></span><a href="#apisix-ingress"><b></b>Apisix Ingress</a></li><li><span class="title-icon "></span><a href="#nginx-ingress"><b></b>Nginx Ingress</a></li></ul><li><span class="title-icon "></span><a href="#&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528;-ingress"><b></b>&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528; Ingress</a></li><ul><li><span class="title-icon "></span><a href="#&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;"><b></b>&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;</a></li><li><span class="title-icon "></span><a href="#&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;"><b></b>&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5B9E;&#x6218;-ingress"><b></b>&#x5B9E;&#x6218; Ingress</a></li><ul><li><span class="title-icon "></span><a href="#&#x90E8;&#x7F72;-web"><b></b>&#x90E8;&#x7F72; web</a></li><li><span class="title-icon "></span><a href="#&#x521B;&#x5EFA;-ingress"><b></b>&#x521B;&#x5EFA; Ingress</a></li><li><span class="title-icon "></span><a href="#&#x516C;&#x7F51;&#x8BBF;&#x95EE;"><b></b>&#x516C;&#x7F51;&#x8BBF;&#x95EE;</a></li></ul><li><span class="title-icon "></span><a href="#ingress-&#x914D;&#x7F6E;"><b></b>Ingress &#x914D;&#x7F6E;</a></li><ul><li><span class="title-icon "></span><a href="#ingress-&#x7ED3;&#x6784;"><b></b>Ingress &#x7ED3;&#x6784;</a></li><li><span class="title-icon "></span><a href="#ingress-&#x7C7B;&#x578B;"><b></b>Ingress &#x7C7B;&#x578B;</a></li></ul></ul></ul></div><h1 id="43-ingress"><a name="43-ingress" class="anchor-navigation-ex-anchor" href="#43-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>4.3 ingress</h1>
<p>&#x5728; 4.1 &#x7AE0;&#x4E2D;&#xFF0C;&#x4ECB;&#x7ECD;&#x4E86; Kubernetes &#x7F51;&#x7EDC;&#x4EE5;&#x53CA; Service &#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x7684;&#x670D;&#x52A1;&#x5728;&#x591A;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x7EDF;&#x4E00;&#x7684;&#x8BBF;&#x95EE;&#x70B9;&#xFF0C;&#x7528;&#x6237;&#x53EA;&#x9700;&#x8981;&#x8BBF;&#x95EE;&#x8FD9;&#x4E2A;&#x5730;&#x5740;&#x5373;&#x53EF;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x6240;&#x6709;&#x670D;&#x52A1;&#x5668;&#x7684; IP &#x5730;&#x5740;&#x3002;&#x4F7F;&#x7528; LoadBalancer &#x662F;&#x4E2A;&#x597D;&#x529E;&#x6CD5;&#xFF0C;&#x4F8B;&#x5982;&#x817E;&#x8BAF;&#x4E91;&#x7684; CLB&#xFF0C;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; IP&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#x8FD9;&#x4E2A; IP &#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x5C06;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x5934;&#x90E8;&#x7684; IP &#x5730;&#x5740;&#x66FF;&#x6362;&#x6210;&#x9700;&#x8981;&#x8BBF;&#x95EE;&#x7684;&#x8282;&#x70B9;&#x670D;&#x52A1;&#x5668;&#x5730;&#x5740;&#x3002;</p>
<div class="mermaid">
flowchart LR
    &#x7528;&#x6237; -- 111.111.111.111 --&gt; LB(LoadBalancer IP)
    LB  -- 222.222.222.1 --&gt; Node1
    LB  -- 222.222.222.2 --&gt; Node2
    LB  -- 222.222.222.3 --&gt; Node3
</div>

<p>&#x8FD9;&#x90E8;&#x5206;&#x8DDF; TCP &#x7684; IP &#x5934;&#x90E8;&#x6709;&#x5173;&#xFF0C;TCP &#x662F;&#x4F20;&#x8F93;&#x5C42;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4F8B;&#x5982;&#x5F53; TCP IP &#x4E3A; 111.111.111.111 &#x65F6;&#xFF0C;&#x7528;&#x6237;&#x7684; TCP &#x6570;&#x636E;&#x62A5;&#x5230;&#x5E95;&#x4E0B;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x8DEF;&#x7531;&#x53EF;&#x4EE5;&#x4FEE;&#x6539; TCP &#x4E2D;&#x7684; IP &#x90E8;&#x5206;&#xFF0C;&#x6539;&#x6210; 222.222.222.1&#xFF0C;&#x8FD9;&#x6837;&#x6B64; TCP &#x6570;&#x636E;&#x62A5;&#x4FBF;&#x4F1A;&#x5BFB;&#x627E; IP &#x4E3A; 222.222.222.1 &#x7684;&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<h2 id="&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;"><a name="&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;</h2>
<p><img src="images/clb1.jpg" alt="clb1"></p>
<p><img src="images/clb2.png" alt="clb2"></p>
<p>&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x6709;&#x4E24;&#x7C7B;&#xFF0C;&#x533A;&#x522B;&#x5728;&#x4E8E;&#x56DB;&#x5C42;&#x7F51;&#x7EDC;&#x548C;&#x4E03;&#x5C42;&#x7F51;&#x7EDC;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x4F20;&#x8F93;&#x5C42;&#x5728;&#x7B2C;&#x56DB;&#x5C42;&#xFF0C;&#x8FD9;&#x5C42;&#x534F;&#x8BAE;&#x6709; TCP/UDP/TCP SSL &#x7B49;&#xFF0C;&#x800C;&#x4E03;&#x5C42;&#x6709; HTTP/HTTPS&#x3002;</p>
<p>&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;&#x50CF;&#x817E;&#x8BAF;&#x4E91;&#x7B49;&#x4E91;&#x670D;&#x52A1;&#x5546;&#xFF0C;&#x4EBA;&#x5BB6;&#x6709;&#x5F88;&#x591A;&#x673A;&#x623F;&#xFF0C;&#x63D0;&#x4F9B; DNS&#xFF0C;NAT &#x8FD9;&#x4E9B;&#x670D;&#x52A1;&#x5F88;&#x6B63;&#x5E38;&#xFF0C;&#x4F46;&#x662F;&#x6B38;&#xFF0C;&#x6211;&#x5C31;&#x662F;&#x4E0D;&#x7528;&#xFF0C;&#x6211;&#x5C31;&#x8981;&#x81EA;&#x5DF1;&#x505A;&#xFF0C;&#x90A3;&#x4F60;&#x53EF;&#x4EE5;&#x7528; Kubernetes &#x4E2D;&#x7684; Ingress &#x6765;&#x505A;&#x3002;</p>
<h3 id="&#x4EC0;&#x4E48;&#x662F;-ingress"><a name="&#x4EC0;&#x4E48;&#x662F;-ingress" class="anchor-navigation-ex-anchor" href="#&#x4EC0;&#x4E48;&#x662F;-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4EC0;&#x4E48;&#x662F; Ingress</h3>
<p>&#x6211;&#x4EEC;&#x505A;&#x7F51;&#x7AD9;&#x65F6;&#xFF0C;&#x4F7F;&#x7528; Nginx &#x505A; Web &#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4F1A;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x5B50;&#x57DF;&#x540D;&#x7ED1;&#x5B9A;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#xFF0C;<code>a.xxx.com</code> &#x7ED1;&#x5B9A; A &#x7F51;&#x7AD9;&#xFF0C;<code>b.xxx.com</code> &#x7ED1;&#x5B9A; B &#x7F51;&#x7AD9;&#xFF0C;&#x8FD9;&#x6837;&#x5728;&#x4E00;&#x4E2A;&#x57DF;&#x540D;&#x7684;&#x4E0D;&#x540C;&#x5B50;&#x57DF;&#x540D;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x4E0D;&#x540C;&#x7684;&#x7AD9;&#x70B9;&#xFF0C;&#x5BF9;&#x4E8E;&#x73B0;&#x5728;&#x7684;&#x5927;&#x591A;&#x6570;&#x4E92;&#x8054;&#x7F51;&#x7F51;&#x7AD9;&#xFF0C;&#x4F9D;&#x7136;&#x4F1A;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x5212;&#x5206;&#x3002;</p>
<p>&#x5728;&#x5FAE;&#x670D;&#x52A1;&#x67B6;&#x6784;&#x4E2D;&#xFF0C;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x90E8;&#x7F72;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x5219;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x90FD;&#x901A;&#x8FC7; <code>xxx.com</code> &#x8FD9;&#x4E2A;&#x57DF;&#x540D;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;&#xFF0C;&#x5C31;&#x597D;&#x50CF;&#x6240;&#x6709;&#x6A21;&#x5757;&#x90FD;&#x5728;&#x4E00;&#x8D77;&#xFF0C;&#x8BA9;&#x7528;&#x6237;&#x611F;&#x89C9;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#x3002;&#x5219;&#x53EF;&#x80FD;&#x4F1A;&#x4F7F;&#x7528;&#x76EE;&#x5F55;&#x8DEF;&#x5F84;&#x5BF9;&#x6A21;&#x5757;&#x8FDB;&#x884C;&#x5212;&#x5206;&#xFF0C;&#x4F8B;&#x5982;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x8981;&#x5B9E;&#x73B0; <code>xxx.com/a</code> &#x8BBF;&#x95EE; A &#x6A21;&#x5757;&#xFF0C;<code>xxx.com/b</code> &#x8BBF;&#x95EE; B &#x6A21;&#x5757;&#xFF0C;&#x4F46;&#x5BF9;&#x7528;&#x6237;&#x6765;&#x8BF4;&#xFF0C;&#x4E00;&#x76F4;&#x5728;&#x8BBF;&#x95EE; <code>xxx.com</code> &#x8FD9;&#x4E2A;&#x57DF;&#x540D;&#x3002;</p>
<p>&#x8FD9;&#x79CD;&#x9700;&#x6C42;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; nginx &#x8FDB;&#x884C;&#x53CD;&#x5411;&#x4EE3;&#x7406;&#xFF0C;&#x800C;&#x5728; Kubernetes &#x4E2D;&#xFF0C;&#x8FD9;&#x79CD;&#x9700;&#x6C42;&#x4E5F;&#x662F;&#x4E00;&#x6A21;&#x4E00;&#x6837;&#x7684;&#x3002;</p>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4E3A; A&#x3001;B&#x3001;C &#x7B49;&#x5E94;&#x7528;&#xFF0C;&#x521B;&#x5EFA;&#x591A;&#x4E2A; Service&#xFF0C;&#x6BCF;&#x4E2A; Service &#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528; Ingress &#x914D;&#x7F6E;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#xFF0C;&#x51B3;&#x5B9A; URL &#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x54EA;&#x4E2A; Service&#x3002;</p>
<p><img src="images/ingress_abc.com.png" alt="ingress_abc.com"></p>
<blockquote>
<p>Ingress &#x516C;&#x5F00;&#x4E86;&#x4ECE;&#x96C6;&#x7FA4;&#x5916;&#x90E8;&#x5230;&#x96C6;&#x7FA4;&#x5185;&#x670D;&#x52A1;&#x7684; HTTP &#x548C; HTTPS &#x8DEF;&#x7531;&#xFF0C;Ingress &#x8D44;&#x6E90;&#x4E0A;&#x5B9A;&#x4E49;&#x7684;&#x89C4;&#x5219;&#x63A7;&#x5236;&#x4E86;&#x8DEF;&#x7531;&#x3002;</p>
</blockquote>
<p>Ingress &#x53EF;&#x4EE5;&#x8BA9;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x591A;&#x4E2A; Service &#x80FD;&#x591F;&#x4ECE;&#x96C6;&#x7FA4;&#x5916;&#x8BBF;&#x95EE;&#xFF0C;Ingress &#x8FD8;&#x63D0;&#x4F9B;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x3001;SSL/TLS &#x548C;&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x670D;&#x52A1;&#x5668;&#x7B49;&#xFF0C;Ingress &#x53EF;&#x4EE5;&#x914D;&#x7F6E;&#x8FB9;&#x7F18;&#x8DEF;&#x7531;&#x5668;&#x6216;&#x5176;&#x4ED6;&#x524D;&#x7AEF;&#x5DE5;&#x5177;&#x6765;&#x5E2E;&#x52A9;&#x5904;&#x7406;&#x7F51;&#x7EDC;&#x6D41;&#x91CF;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x822C;&#x90FD;&#x662F;&#x901A;&#x81EA;&#x5DF1;&#x7684;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x6765;&#x5B9E;&#x73B0;&#x3002;</p>
<p>Ingress &#x6709;&#x4E24;&#x90E8;&#x5206;&#xFF0C;&#x4E00;&#x90E8;&#x5206;&#x662F; LoadBalancer &#xFF0C;&#x63D0;&#x4F9B;&#x7EDF;&#x4E00;&#x5165;&#x53E3;&#xFF0C;&#x4EE3;&#x7406;&#x8BF7;&#x6C42;&#xFF1B;&#x53E6;&#x4E00;&#x90E8;&#x5206;&#x662F; Ingress &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x590D;&#x5236;&#x5B9A;&#x4E49;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#x7B49;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4E0D;&#x4F7F;&#x7528;&#x516C;&#x6709;&#x4E91;&#x5E73;&#x53F0;&#x7684; LoadBalancer &#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x81EA;&#x5DF1;&#x642D;&#x5EFA;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x8FD9;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x52A0;&#x5165;&#x5230; Kubernetes &#x96C6;&#x7FA4;&#x4E2D;&#xFF0C;&#x505A;&#x6D41;&#x91CF;&#x5165;&#x53E3;&#xFF0C;&#x8FD9;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x7F51;&#x7EDC;&#x63A5;&#x53E3;&#x5FC5;&#x987B;&#x591F;&#x5927;&#xFF0C;&#x6297;&#x5F97;&#x4F4F;&#x6D41;&#x91CF;&#x3002;</p>
<h3 id="ingress-&#x4E0E;-service"><a name="ingress-&#x4E0E;-service" class="anchor-navigation-ex-anchor" href="#ingress-&#x4E0E;-service"><i class="fa fa-link" aria-hidden="true"></i></a>Ingress &#x4E0E; Service</h3>
<p>&#x5728;&#x524D;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x5B66;&#x4E60;&#x5230;&#x4E86; Service&#xFF0C;&#x901A;&#x8FC7; Service &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x66B4;&#x9732;&#x4E00;&#x4E2A;&#x7AEF;&#x53E3;&#x5230;&#x5916;&#x7F51;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x7AEF;&#x53E3;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5E94;&#x7528;&#x3002;</p>
<p>&#x5176;&#x4E2D;&#xFF0C;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x66B4;&#x9732; Service&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x5176;&#x88AB;&#x96C6;&#x7FA4;&#x5916;&#x90E8;&#x8BBF;&#x95EE;&#xFF1A;</p>
<ul>
<li>&#x4F7F;&#x7528; <code>Service.Type=LoadBalancer</code></li>
<li>&#x4F7F;&#x7528; <code>Service.Type=NodePort</code></li>
</ul>
<p>Service &#x7684;&#x8BBF;&#x95EE;&#x65B9;&#x5F0F;&#x662F; IP&#xFF0C;&#x6BCF;&#x6B21;&#x8981;&#x5C06;&#x670D;&#x52A1;&#x516C;&#x5F00;&#x7ED9;&#x5916;&#x754C;&#x65F6;&#xFF0C;&#x90FD;&#x5FC5;&#x987B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684; LoadBalancer &#x5E76;&#x5411;&#x4E91;&#x670D;&#x52A1;&#x5546;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x516C;&#x7F51; IP &#x5730;&#x5740;&#x3002;&#x6216;&#x8005;&#x4F7F;&#x7528; <code>NodePort</code>&#xFF0C;&#x4F46;&#x662F;&#x53EA;&#x80FD;&#x5728;&#x4E00;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x88AB;&#x8BBF;&#x95EE;&#xFF0C;&#x800C;&#x4E14; Service &#x53EA;&#x80FD;&#x4E3A;&#x4E00;&#x79CD; Pod &#x670D;&#x52A1;&#xFF0C;&#x66B4;&#x9732;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x7AEF;&#x53E3;&#xFF0C;&#x90A3;&#x4E48; N &#x4E2A;&#x670D;&#x52A1;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x521B;&#x5EFA; N &#x4E2A; Service&#x3002;Service &#x867D;&#x7136;&#x80FD;&#x591F;&#x516C;&#x5F00;&#x7AEF;&#x53E3;&#x5230;&#x5916;&#x90E8;&#x7F51;&#x7EDC;&#x4E2D;&#xFF0C;&#x4F46;&#x662F;&#x65E0;&#x6CD5;&#x5C06;&#x8FD9;&#x4E9B;&#x670D;&#x52A1;&#x5408;&#x5E76;&#x5230;&#x4E00;&#x4E2A; <code>example.com/{&#x670D;&#x52A1;}</code> &#x4E2D;&#x8BBF;&#x95EE;&#xFF0C;Service &#x9700;&#x8981;&#x901A;&#x8FC7;&#x4E0D;&#x540C;&#x7684;&#x7AEF;&#x53E3;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F60;&#x6709;&#x4E00;&#x4E2A; <code>example.com</code> &#x57DF;&#x540D;&#xFF0C;&#x4F60;&#x90E8;&#x7F72;&#x4E86;&#x591A;&#x4E2A; Web &#x670D;&#x52A1;&#xFF0C;&#x5176;&#x4E2D;&#x6709;&#x4E24;&#x4E2A;&#x5B50;&#x6A21;&#x5757;&#x5206;&#x522B;&#x4E3A;&#x8BFE;&#x7A0B;(course)&#x3001;&#x8003;&#x8BD5;(exam) &#x4E24;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8FD9;&#x4E9B;&#x6A21;&#x5757;&#x6784;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x57F9;&#x8BAD;&#x7F51;&#x7AD9;&#x3002;&#x6B64;&#x65F6;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x8BBF;&#x95EE; <code>example.com/api/course</code> &#x80FD;&#x591F;&#x8BBF;&#x95EE;&#x8BFE;&#x7A0B;&#x5B66;&#x4E60;&#x6A21;&#x5757;&#xFF0C;&#x8BBF;&#x95EE; <code>example.com/api/exam</code> &#x80FD;&#x591F;&#x8BBF;&#x95EE;&#x8003;&#x8BD5;&#x6A21;&#x5757;&#x3002;&#x663E;&#x7136;&#xFF0C;Service &#x662F;&#x65E0;&#x6CD5;&#x505A;&#x5230;&#x7684;&#x3002;</p>
<p>&#x4F7F;&#x7528; Ingress &#xFF0C;&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x8BBE;&#x7F6E;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#xFF0C;&#x800C;&#x4E14;&#x65E0;&#x9700;&#x521B;&#x5EFA;&#x4E00;&#x5806; LoadBalancers/Nodes &#x516C;&#x5F00;&#x6BCF;&#x4E2A;&#x670D;&#x52A1;&#xFF0C;&#x5E76;&#x4E14; Ingress &#x672C;&#x8EAB;&#x5177;&#x6709;&#x5F88;&#x591A;&#x529F;&#x80FD;&#x3002;</p>
<blockquote>
<p>Ingress &#x4E5F;&#x9700;&#x8981; Service &#x3002;</p>
</blockquote>
<h2 id="&#x5B89;&#x88C5;-ingress-&#x63A7;&#x5236;&#x5668;"><a name="&#x5B89;&#x88C5;-ingress-&#x63A7;&#x5236;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x5B89;&#x88C5;-ingress-&#x63A7;&#x5236;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B89;&#x88C5; Ingress &#x63A7;&#x5236;&#x5668;</h2>
<p>Ingress &#x63A7;&#x5236;&#x5668;&#x6709;&#x591A;&#x79CD;&#x5B9E;&#x73B0;&#xFF0C;&#x5176;&#x4E2D; Kubernetes &#x5B98;&#x65B9;&#x6709;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; Ingress-nginx &#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x5176;&#x5B83;&#x5B9E;&#x73B0;&#x8FD8;&#x6709; Kong Ingress&#x3001;Traefik&#x3001;HAProxy Ingress &#x7B49;&#xFF0C;&#x5728;&#x672C;&#x7AE0;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5B89;&#x88C5;&#x4F7F;&#x7528; Apisix Ingress &#x6216; Nginx Ingress&#xFF0C;&#x4F46;&#x662F;&#x53EA;&#x4F7F;&#x7528; Nginx Ingress &#x505A;&#x6F14;&#x793A;&#xFF0C;&#x5176;&#x5B83;&#x63A7;&#x5236;&#x5668;&#x8BF7;&#x53C2;&#x8003;&#x5B98;&#x65B9;&#x6587;&#x6863;&#xFF1A; <a href="https://kubernetes.github.io/ingress-nginx/deploy/#provider-specific-steps" target="_blank">https://kubernetes.github.io/ingress-nginx/deploy/#provider-specific-steps</a></p>
<h3 id="apisix-ingress"><a name="apisix-ingress" class="anchor-navigation-ex-anchor" href="#apisix-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>Apisix Ingress</h3>
<p>Helm &#x662F;&#x4E00;&#x4E2A; Kubernetes &#x4E0A;&#x7684;&#x6253;&#x5305;&#x5DE5;&#x5177;&#xFF0C;&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x4E2D;&#x5DF2;&#x7ECF;&#x6709; Helm&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x901A;&#x8FC7; Helm &#x5DE5;&#x5177;&#x5B89;&#x88C5; Apisix&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token function">sudo</span> snap <span class="token function">install</span> helm --classic
</code></pre>
<pre class="language-"><code class="lang-bash">helm repo <span class="token function">add</span> apisix https://charts.apiseven.com
helm repo update
kubectl create ns ingress-apisix
helm <span class="token function">install</span> apisix apisix/apisix <span class="token punctuation">\</span>
  --set gateway.type<span class="token operator">=</span>NodePort <span class="token punctuation">\</span>
  --set ingress-controller.enabled<span class="token operator">=</span>true <span class="token punctuation">\</span>
  --namespace ingress-apisix

kubectl get <span class="token function">service</span> --namespace ingress-apisix
</code></pre>
<p>&#x5B89;&#x88C5; dashboard&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">helm <span class="token function">install</span> apisix-dashboard apisix/apisix-dashboard --namespace ingress-apisix
</code></pre>
<p>&#x7136;&#x540E;&#x4F1A;&#x63D0;&#x793A;&#x4F60;&#x6267;&#x884C;&#x4E00;&#x4E9B;&#x547D;&#x4EE4;&#xFF0C;&#x5C06;&#x547D;&#x4EE4;&#x590D;&#x5236;&#x5230;&#x90E8;&#x7F72;&#x4E86; dashboard &#x7684;&#x8282;&#x70B9;&#x8FD0;&#x884C;&#x3002;</p>
<p>&#x5B89;&#x88C5; Apisix Ingress &#x63A7;&#x5236;&#x5668;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">helm <span class="token function">install</span> apisix-ingress-controller apisix/apisix-ingress-controller --namespace ingress-apisix
</code></pre>
<p>&#x67E5;&#x770B;&#x8FD9;&#x4E9B;&#x7EC4;&#x4EF6;&#x7684; Service&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get  services --namespace=ingress-apisix</span>
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>             AGE
apisix-admin                ClusterIP   <span class="token number">10.96</span>.38.188     <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">9180</span>/TCP            105s
apisix-dashboard            ClusterIP   <span class="token number">10.111</span>.179.134   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>/TCP              37s
apisix-etcd                 ClusterIP   <span class="token number">10.98</span>.124.145    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">2379</span>/TCP,2380/TCP   105s
apisix-etcd-headless        ClusterIP   None             <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">2379</span>/TCP,2380/TCP   105s
apisix-gateway              NodePort    <span class="token number">10.100</span>.83.155    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>:30712/TCP        105s
apisix-ingress-controller   ClusterIP   <span class="token number">10.108</span>.233.236   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>/TCP              20s
</code></pre>
<p>&#x4FEE;&#x6539; apisix-dashboard &#x7684; Service &#x7C7B;&#x578B;&#x4E3A; NodePort&#x3002;</p>
<pre class="language-"><code>kubectl edit service apisix-dashboard --namespace ingress-apisix
</code></pre><pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get  services --namespace=ingress-apisix</span>
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>             AGE
apisix-admin                ClusterIP   <span class="token number">10.96</span>.38.188     <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">9180</span>/TCP            2m31s
apisix-dashboard            NodePort    <span class="token number">10.111</span>.179.134   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>:31429/TCP        83s
apisix-etcd                 ClusterIP   <span class="token number">10.98</span>.124.145    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">2379</span>/TCP,2380/TCP   2m31s
apisix-etcd-headless        ClusterIP   None             <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">2379</span>/TCP,2380/TCP   2m31s
apisix-gateway              NodePort    <span class="token number">10.100</span>.83.155    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>:30712/TCP        2m31s
apisix-ingress-controller   ClusterIP   <span class="token number">10.108</span>.233.236   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>/TCP              66s
</code></pre>
<p>&#x67E5;&#x770B; apisix-dashboard &#x5B89;&#x88C5;&#x5230;&#x4E86;&#x54EA;&#x91CC;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment">#  kubectl get pods --namespace ingress-apisix -o wide</span>
NAME                                         READY   STATUS             RESTARTS      AGE     IP          NODE     NOMINATED 
apisix-dashboard-66b4ddb8b8-zcgs4            <span class="token number">0</span>/1     CrashLoopBackOff   <span class="token number">4</span> <span class="token punctuation">(</span>66s ago<span class="token punctuation">)</span>   3m15s   <span class="token number">10.44</span>.0.4   master   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
</code></pre>
<p>&#x7531;&#x4E8E;&#x5176;&#x90E8;&#x7F72;&#x5728; master &#x8282;&#x70B9;&#x4E0A;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; master &#x7684;&#x516C;&#x7F51; IP &#x8BBF;&#x95EE;&#x5B83;&#x3002;</p>
<p>&#x67E5;&#x627E;&#x5176;&#x6620;&#x5C04;&#x5230;&#x8282;&#x70B9;&#x7684;&#x7AEF;&#x53E3;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get service --namespace ingress-apisix</span>
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>             AGE
apisix-dashboard            NodePort    <span class="token number">10.109</span>.51.102    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>:32026/TCP        5m25s
</code></pre>
<blockquote>
<p>&#x8BF7;&#x81EA;&#x884C;&#x53C2;&#x8003;&#x914D;&#x7F6E; pvc&#xFF0C;<a href="https://apisix.apache.org/zh/docs/ingress-controller/deployments/minikube" target="_blank">https://apisix.apache.org/zh/docs/ingress-controller/deployments/minikube</a></p>
</blockquote>
<p>&#x5378;&#x8F7D;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code>helm uninstall apisix apisix-dashboard  apisix-ingress-controller  --namespace=ingress-apisix
</code></pre><blockquote>
<p><strong>[Info] &#x63D0;&#x793A;</strong></p>
<p>&#x7531;&#x4E8E; Apisix Ingress &#x914D;&#x7F6E;&#x590D;&#x6742;&#xFF0C;&#x7B14;&#x8005;&#x5DF2;&#x7ECF;&#x653E;&#x5F03;&#x5C1D;&#x8BD5;&#x3002;</p>
</blockquote>
<h3 id="nginx-ingress"><a name="nginx-ingress" class="anchor-navigation-ex-anchor" href="#nginx-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>Nginx Ingress</h3>
<p>&#x901A;&#x8FC7; Helm &#x5DE5;&#x5177;&#x5B89;&#x88C5; ingress-nginx&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">helm repo <span class="token function">add</span> ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

helm upgrade --install ingress-nginx ingress-nginx <span class="token punctuation">\</span>
  --repo https://kubernetes.github.io/ingress-nginx <span class="token punctuation">\</span>
  --namespace ingress-nginx --create-namespace
</code></pre>
<p>&#x68C0;&#x6D4B;&#x5B89;&#x88C5;&#x7684;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token assign-left variable">POD_NAME</span><span class="token operator">=</span><span class="token variable"><span class="token variable">$(</span>kubectl get pods -l app.kubernetes.io/name<span class="token operator">=</span>ingress-nginx -o <span class="token assign-left variable">jsonpath</span><span class="token operator">=</span><span class="token string">&apos;{.items[0].metadata.name}&apos;</span><span class="token variable">)</span></span>
kubectl <span class="token builtin class-name">exec</span> -it <span class="token variable">$POD_NAME</span> -- /nginx-ingress-controller --version
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x6709;&#x6210;&#x529F;&#x5B89;&#x88C5; ingress-nginx &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x5B89;&#x88C5; ingress &#x63A7;&#x5236;&#x5668;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x5728; kube-system &#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4F1A;&#x6709;&#x76F8;&#x5173;&#x7684; Pod &#x51FA;&#x73B0;&#x3002;</p>
<pre class="language-"><code>kubectl get services --all-namespaces
</code></pre><pre class="language-"><code>default       ingress-nginx-controller             LoadBalancer   10.108.196.41    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>pending</span><span class="token punctuation">&gt;</span></span>     80:30973/TCP,443:32341/TCP   
default       ingress-nginx-controller-admission   ClusterIP      10.99.253.53     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>        443/TCP
</code></pre><p>&#x5176;&#x4E2D; ingress-nginx-controller &#x5DF2;&#x88AB;&#x6620;&#x5C04;&#x5230;&#x8282;&#x70B9;&#x7684; 30973 &#x7AEF;&#x53E3;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x516C;&#x7F51; IP &#x8BBF;&#x95EE;&#x3002;</p>
<p><img src="images/ingress_nodeport.jpg" alt="ingress_nodeport"></p>
<h2 id="&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528;-ingress"><a name="&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528;-ingress" class="anchor-navigation-ex-anchor" href="#&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528;-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>&#x521B;&#x5EFA;&#x548C;&#x4F7F;&#x7528; Ingress</h2>
<h3 id="&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;"><a name="&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;" class="anchor-navigation-ex-anchor" href="#&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;</h3>
<p>&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x5FEB;&#x901F;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684; Ingress &#x8DEF;&#x7531;&#xFF0C;&#x7EC3;&#x4E60;&#x4E00;&#x4E0B;&#x3002;</p>
<p>&#x521B;&#x5EFA; Pod&#xFF1A;</p>
<pre class="language-"><code>kubectl create deployment nginx --image=nginx:latest --replicas=3
</code></pre><p>&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x521B;&#x5EFA; Service&#xFF1A;</p>
<pre class="language-"><code>kubectl expose deployment nginx --type=NodePort --port=8080 --target-port=80
</code></pre><p>&#x521B;&#x5EFA; Ingress &#x670D;&#x52A1;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> networking.k8s.io/v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Ingress
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> test<span class="token punctuation">-</span>ingress
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">rules</span><span class="token punctuation">:</span> 
  <span class="token punctuation">-</span> <span class="token key atrule">host</span><span class="token punctuation">:</span> k1.whuanle.cn
  <span class="token key atrule">defaultBackend</span><span class="token punctuation">:</span>
    <span class="token key atrule">service</span><span class="token punctuation">:</span>
      <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
      <span class="token key atrule">port</span><span class="token punctuation">:</span>
        <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">8080</span>
</code></pre>
<blockquote>
<p>&#x5982;&#x679C;&#x6267;&#x884C; <code>kubectl apply -f</code> &#x65F6;&#x51FA;&#x73B0;&#x95EE;&#x9898;&#xFF0C;&#x8BF7;&#x53C2;&#x8003;&#x4E0B;&#x4E00;&#x5C0F;&#x8282;&#x3002;</p>
<p>k1.whuanle.cn &#x662F;&#x7B14;&#x8005;&#x7684;&#x57DF;&#x540D;&#x3002;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x5C06;&#x57DF;&#x540D;&#x89E3;&#x6790;&#x5230;&#x90E8;&#x7F72;&#x4E86; ingress &#x7684;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x3002;</p>
</blockquote>
<p>&#x83B7;&#x53D6; ingress&#xFF1A;</p>
<pre class="language-"><code>root@instance-2:~# kubectl get ingress
NAME           CLASS    HOSTS           ADDRESS   PORTS   AGE
test-ingress   nginx   k1.whuanle.cn   10.99.63.81   80      3m37s
</code></pre><p>ADDRESS &#x53EF;&#x80FD;&#x5728;1&#x5206;&#x949F;&#x540E;&#x624D;&#x4F1A;&#x751F;&#x6210;&#xFF0C;&#x5982;&#x679C;&#x5176;&#x6CA1;&#x6709;&#x81EA;&#x52A8;&#x751F;&#x6210; <code>ADDRESS</code>&#xFF0C;&#x8FD9;&#x91CC;&#x53EF;&#x80FD;&#x6682;&#x65F6;&#x4E0D;&#x80FD;&#x8BBF;&#x95EE;&#xFF0C;&#x540E;&#x9762;&#x4F1A;&#x63D0;&#x53CA;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;</p>
<blockquote>
<p>&#x56E0;&#x4E3A; 10.99.63.81 &#x4E0D;&#x662F;&#x516C;&#x7F51; IP&#xFF0C;&#x57DF;&#x540D;&#x4E0D;&#x80FD;&#x89E3;&#x6790;&#x5230;&#x6B64; IP &#x4E0A;&#x3002;&#x6240;&#x4EE5;&#x6B64;&#x65F6;&#x8FD8;&#x662F;&#x76F8;&#x5F53;&#x4E8E;&#x8BBF;&#x95EE; IP:&#x7AEF;&#x53E3;&#xFF0C;ingress &#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x4E0D;&#x8D77;&#x4F5C;&#x7528;&#x3002;</p>
<p>&#x6B64;&#x5730;&#x5740;&#x540C;&#x65F6;&#x662F; ingress &#x63A7;&#x5236;&#x5668;&#x7684;&#x5730;&#x5740;&#x3002;</p>
</blockquote>
<p>&#x6309;&#x7167; NodePort &#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x57DF;&#x540D;&#x8BBF;&#x95EE;&#x540E;&#x7AEF;&#x670D;&#x52A1;&#x3002;</p>
<p><img src="images/k1.jpg" alt="k1"></p>
<h3 id="&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;"><a name="&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;" class="anchor-navigation-ex-anchor" href="#&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x89E3;&#x51B3;&#x5C0F;&#x95EE;&#x9898;</h3>
<p>&#x5982;&#x679C;&#x5E94;&#x7528; YAML &#x6587;&#x4EF6;&#x521B;&#x5EFA; Ingress &#x65F6;&#xFF0C;&#x51FA;&#x73B0;&#x4E0B;&#x9762;&#x7684;&#x63D0;&#x793A;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x505A;&#x4E9B;&#x4FEE;&#x6539;&#x624D;&#x80FD;&#x6210;&#x529F;&#x521B;&#x5EFA; ingress&#x3002;&#x6216;&#x8005;&#x591A;&#x8BD5;&#x51E0;&#x6B21;&#x3002;</p>
<p><img src="images/create_ingress.jpg" alt="create_ingress"></p>
<pre class="language-"><code>Error from server (InternalError): error when creating &quot;ingress.yaml&quot;: Internal error occurred: failed calling webhook &quot;validate.nginx.ingress.kubernetes.io&quot;: Post &quot;https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1beta1/ingresses?timeout=10s&quot;: dial tcp 10.98.246.133:443: i/o timeout
</code></pre><p>&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x67E5;&#x770B; webhook</p>
<pre class="language-"><code>kubectl get validatingwebhookconfigurations
</code></pre><pre class="language-"><code>NAME                      WEBHOOKS   AGE
ingress-nginx-admission   1          4h5m
</code></pre><p>&#x5220;&#x9664; ingress-nginx-admission &#xFF1A;</p>
<pre class="language-"><code>kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
</code></pre><p>&#x63A5;&#x7740;&#x91CD;&#x65B0;&#x521B;&#x5EFA; Ingress &#x5373;&#x53EF;&#x3002;</p>
<p>&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B9E;&#x9645;&#x521B;&#x5EFA; Ingress&#xFF0C;&#x5728;&#x672C;&#x5C0F;&#x8282;&#x4E2D;&#xFF0C;&#x5C06;&#x4F7F;&#x7528; <code>hello-world.info</code> &#x57DF;&#x540D;&#xFF0C;&#x901A;&#x8FC7; <code>/web1</code> &#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#xFF0C;<code>web2</code> &#x8BBF;&#x95EE;&#x53E6;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#x3002;</p>
<p>&#x5220;&#x9664;&#x4E4B;&#x524D;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl delete deployment nginx
kubectl delete svc nginx
kubectl delete ingress test-ingress
</code></pre>
<h2 id="&#x5B9E;&#x6218;-ingress"><a name="&#x5B9E;&#x6218;-ingress" class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x6218;-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x6218; Ingress</h2>
<h3 id="&#x90E8;&#x7F72;-web"><a name="&#x90E8;&#x7F72;-web" class="anchor-navigation-ex-anchor" href="#&#x90E8;&#x7F72;-web"><i class="fa fa-link" aria-hidden="true"></i></a>&#x90E8;&#x7F72; web</h3>
<p>&#x4F7F;&#x7528; Kubernetes &#x5B98;&#x65B9;&#x7684;&#x5BB9;&#x5668;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Hello world &#x7684;&#x7F51;&#x7AD9;&#x5E94;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl create deployment web1 --image<span class="token operator">=</span>gcr.io/google-samples/hello-app:1.0 --replicas<span class="token operator">=</span><span class="token number">3</span>
kubectl create deployment web2 --image<span class="token operator">=</span>gcr.io/google-samples/hello-app:1.0 --replicas<span class="token operator">=</span><span class="token number">3</span>
</code></pre>
<p>&#x521B;&#x5EFA; Service&#xFF0C;&#x66B4;&#x9732;&#x7AEF;&#x53E3;:</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Service
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> web1
  <span class="token key atrule">name</span><span class="token punctuation">:</span> web1
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> http
    <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8080</span>
    <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
    <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">8080</span>
  <span class="token key atrule">selector</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> web1
  <span class="token key atrule">type</span><span class="token punctuation">:</span> NodePort
<span class="token punctuation">---</span>
<span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Service
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> web2
  <span class="token key atrule">name</span><span class="token punctuation">:</span> web2
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> http
    <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">9090</span>
    <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
    <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">8080</span>
  <span class="token key atrule">selector</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> web2
  <span class="token key atrule">type</span><span class="token punctuation">:</span> NodePort
</code></pre>
<blockquote>
<p>&#x6216;&#x4F7F;&#x7528; </p>
<pre class="language-"><code>kubectl expose deployment web1 --type=NodePort --port=8080
kubectl expose deployment web2 --type=NodePort --port=8080
</code></pre></blockquote>
<p>&#x67E5;&#x770B; Service &#x4FE1;&#x606F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">NAME        TYPE      CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span> 
web1           NodePort    <span class="token number">10.100</span>.137.80    <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">8080</span>:31901/TCP  
web2           NodePort    <span class="token number">10.105</span>.184.142   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">9090</span>:31631/TCP
</code></pre>
<p>&#x901A;&#x8FC7; ClusterIP &#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5BF9;&#x4E8E;&#x7684; nginx &#x5E94;&#x7528;&#xFF0C;&#x5176;&#x7AEF;&#x53E3;&#x4E3A; 8080 &#x6216; 9090&#x3002;&#x65E2;&#x7136;&#x8981;&#x521B;&#x5EFA; Ingress&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x4E0D;&#x9700;&#x8981;&#x5173;&#x5FC3; NodePort &#x7AEF;&#x53E3;&#x4E86;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x77E5;&#x9053; 8080&#x3001;9090 &#x5373;&#x53EF;&#x3002;</p>
<h3 id="&#x521B;&#x5EFA;-ingress"><a name="&#x521B;&#x5EFA;-ingress" class="anchor-navigation-ex-anchor" href="#&#x521B;&#x5EFA;-ingress"><i class="fa fa-link" aria-hidden="true"></i></a>&#x521B;&#x5EFA; Ingress</h3>
<p>&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x4E3A; Ingress &#x914D;&#x7F6E;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#xFF0C;&#x8BBF;&#x95EE; <code>/web1</code>&#x3001;<code>/web2</code> &#x65F6;&#xFF0C;&#x662F;&#x5728;&#x8BBF;&#x95EE;&#x4E0D;&#x540C;&#x7684;&#x5E94;&#x7528;&#xFF0C;&#x5176;&#x4E2D;&#x6211;&#x4EEC;&#x7EA6;&#x5B9A;&#xFF0C;&#x8981;&#x7ED1;&#x5B9A;&#x7684;&#x57DF;&#x540D;&#x662F; hello-world.info&#x3002;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> networking.k8s.io/v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Ingress
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> test<span class="token punctuation">-</span>ingress
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">ingressClassName</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">host</span><span class="token punctuation">:</span> hello<span class="token punctuation">-</span>world.info
      <span class="token key atrule">http</span><span class="token punctuation">:</span>
        <span class="token key atrule">paths</span><span class="token punctuation">:</span>
          <span class="token punctuation">-</span> <span class="token key atrule">path</span><span class="token punctuation">:</span> /web1
            <span class="token key atrule">pathType</span><span class="token punctuation">:</span> Prefix
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web1
                <span class="token key atrule">port</span><span class="token punctuation">:</span>
                  <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">8080</span>
          <span class="token punctuation">-</span> <span class="token key atrule">path</span><span class="token punctuation">:</span> /web2
            <span class="token key atrule">pathType</span><span class="token punctuation">:</span> Prefix
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web2
                <span class="token key atrule">port</span><span class="token punctuation">:</span>
                  <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">9090</span>
</code></pre>
<blockquote>
<p>&#x5F53;&#x8BBF;&#x95EE; <a href="http://hello-world.info/web1" target="_blank">http://hello-world.info/web1</a> &#x65F6;&#xFF0C;&#x4F1A;&#x5BFC;&#x5411; Service Web1&#xFF0C;&#x63A5;&#x7740;&#x7531; Service &#x5BFC;&#x5411; Pod&#x3002;</p>
</blockquote>
<p>&#x7B49;&#x5341;&#x6765;&#x79D2;&#x949F;&#xFF0C;&#x7136;&#x540E;&#x67E5;&#x770B; ingress &#x5217;&#x8868;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get ingress</span>
NAME           CLASS   HOSTS              ADDRESS       PORTS   AGE
test-ingress   nginx   hello-world.info   <span class="token number">10.99</span>.63.81   <span class="token number">80</span>      3m37s
</code></pre>
<p>ADDRESS &#x4E2D;&#x7684;&#x662F;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x8BB0;&#x4E0B;&#x6B64;&#x5730;&#x5740;&#xFF0C;&#x6211;&#x4EEC;&#x8981;&#x5C06; hello-world.info &#x8FD9;&#x4E2A;&#x57DF;&#x540D;&#x89E3;&#x6790;&#x5230; 10.99.63.81 &#xFF0C;&#x624D;&#x80FD;&#x63A5;&#x7740;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x67E5;&#x770B; Ingress&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"> kubectl describe ingress test-ingress
</code></pre>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment">#  kubectl describe ingress test-ingress</span>
Name:             test-ingress
Namespace:        default
Address:          <span class="token number">10.99</span>.63.81
Default backend:  default-http-backend:80 <span class="token punctuation">(</span><span class="token operator">&lt;</span>error: endpoints <span class="token string">&quot;default-http-backend&quot;</span> not found<span class="token operator">&gt;</span><span class="token punctuation">)</span>
Rules:
  Host           Path  Backends
  ----           ----  --------
  k1.whuanle.cn  
                 /       web1:8080 <span class="token punctuation">(</span><span class="token number">10.32</span>.0.12:80,10.32.0.13:80,10.32.0.16:80<span class="token punctuation">)</span>
                 /web2   web2:9090 <span class="token punctuation">(</span><span class="token number">10.32</span>.0.11:80,10.32.0.14:80,10.32.0.15:80<span class="token punctuation">)</span>
Annotations:     <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
Events:
  Type    Reason  Age                    From                      Message
  ----    ------  ----                   ----                      -------
  Normal  Sync    6m53s <span class="token punctuation">(</span>x2 over 7m26s<span class="token punctuation">)</span>  nginx-ingress-controller  Scheduled <span class="token keyword">for</span> <span class="token function">sync</span>
  Normal  Sync    5m53s <span class="token punctuation">(</span>x2 over 5m53s<span class="token punctuation">)</span>  nginx-ingress-controller  Scheduled <span class="token keyword">for</span> <span class="token function">sync</span>
</code></pre>
<p>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x4E3A; Ingress &#x63D0;&#x4F9B;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x7684;&#x516C;&#x7F51; IP &#xFF0C;&#x56E0;&#x6B64;&#x6CA1;&#x529E;&#x6CD5;&#x7ED1;&#x5B9A;&#x57DF;&#x540D;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x5185;&#x7F51;&#x7684; DNS&#xFF0C;&#x4F7F;&#x5F97;&#x5728;&#x5185;&#x7F51;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x57DF;&#x540D;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x6253;&#x5F00; <code>/etc/hosts</code> &#x6587;&#x4EF6;&#xFF0C;&#x6DFB;&#x52A0;&#x4E00;&#x884C;&#xFF1A;</p>
<pre class="language-"><code>10.99.63.81 hello-world.info
</code></pre><blockquote>
<p><strong>[Error] &#x63D0;&#x793A;</strong></p>
<p>&#x7531;&#x4E8E;&#x524D;&#x9762;&#x4F7F;&#x7528;&#x4E86; Deployment &#x90E8;&#x7F72;&#x670D;&#x52A1;&#xFF0C;&#x53EA;&#x6709;&#x4E00;&#x90E8;&#x5206;&#x8282;&#x70B9;&#x90E8;&#x7F72;&#x5230;&#x4E86; Pod&#xFF0C;&#x672A;&#x88AB;&#x90E8;&#x7F72; Pod &#x7684;&#x8282;&#x70B9;&#xFF0C;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x6B64; IP &#x8BBF;&#x95EE; Pod&#x3002;&#x56E0;&#x6B64;&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x53EA;&#x80FD;&#x5728;&#x90E8;&#x7F72;&#x4E86; Pod &#x7684;&#x8282;&#x70B9;&#x4E0A;&#x751F;&#x6548;&#x3002;</p>
</blockquote>
<p>&#x4E4B;&#x540E;&#x76F4;&#x63A5;&#x8BBF;&#x95EE; <code>curl http://hello-world.info/web1</code> &#x3001;<code>curl http://hello-world.info/web2</code> &#xFF0C;&#x4FBF;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5230;&#x5177;&#x4F53;&#x7684; Pod &#x670D;&#x52A1;&#x3002;</p>
<p><img src="images/hello-world.info.jpg" alt="hello-world.info"></p>
<h3 id="&#x516C;&#x7F51;&#x8BBF;&#x95EE;"><a name="&#x516C;&#x7F51;&#x8BBF;&#x95EE;" class="anchor-navigation-ex-anchor" href="#&#x516C;&#x7F51;&#x8BBF;&#x95EE;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x516C;&#x7F51;&#x8BBF;&#x95EE;</h3>
<p>&#x7531;&#x4E8E;&#x6CA1;&#x6709;&#x516C;&#x7F51;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#xFF0C;&#x4E0A;&#x9762;&#x7B14;&#x8005;&#x7684; Ingress  &#x521B;&#x5EFA;&#x7684; &#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668; IP &#x662F;&#x96C6;&#x7FA4;&#x5185;&#x7684;&#xFF0C;&#x5730;&#x5740;&#x662F; 10.99.63.81&#xFF0C;&#x8FD9;&#x4E2A;&#x5730;&#x5740;&#x5176;&#x5B9E;&#x5C31;&#x662F; Ingress &#x63A7;&#x5236;&#x5668;&#x7684; Service IP&#x3002;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get svc -n ingress-nginx</span>
NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>                      AGE
ingress-nginx-controller             NodePort    <span class="token number">10.99</span>.63.81     <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>:32587/TCP,443:31520/TCP   23h
ingress-nginx-controller-admission   ClusterIP   <span class="token number">10.106</span>.108.53   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">443</span>/TCP                      23h
</code></pre>
<p>&#x5982;&#x679C;&#x5728;&#x96C6;&#x7FA4;&#x4E2D;&#x8BBF;&#x95EE;&#xFF0C;&#x5219;&#x53EA;&#x9700;&#x8981;&#x6620;&#x5C04; 10.99.63.81 &#x7136;&#x540E;&#x8BBF;&#x95EE; 80 &#x7AEF;&#x53E3;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x5982;&#x679C;&#x662F;&#x516C;&#x7F51;&#x8BBF;&#x95EE;&#xFF0C;&#x4E5F;&#x6709;&#x529E;&#x6CD5;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x65F6; Service NodePort &#x662F; 32587&#xFF0C;&#x90A3;&#x4E48;&#x4F7F;&#x7528;&#x57DF;&#x540D;&#x89E3;&#x6790;&#x5230;&#x8282;&#x70B9; IP&#xFF0C;&#x5728;&#x4F7F;&#x7528;&#x6B64;&#x7AEF;&#x53E3;&#x8BBF;&#x95EE;&#x5373;&#x53EF;&#x3002;</p>
<p><img src="images/public_domain_ingress.png" alt="image-20211108195004695"></p>
<h2 id="ingress-&#x914D;&#x7F6E;"><a name="ingress-&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#ingress-&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>Ingress &#x914D;&#x7F6E;</h2>
<p>&#x5728;&#x524D;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E00;&#x4E2A; Ingress &#x5173;&#x8054;&#x4E86;&#x591A;&#x4E2A; Service&#xFF0C;&#x5176;&#x7B80;&#x5316; YAML &#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
        <span class="token punctuation">...</span> <span class="token punctuation">...</span>
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web1
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web2
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x8FD9;&#x4E2A; Ingress &#x5173;&#x8054;&#x4E86; Service&#xFF0C;&#x4E0D;&#x8FC7;&#xFF0C;Ingress &#x5E76;&#x4E0D;&#x662F;&#x901A;&#x8FC7; Service &#x8F6C;&#x53D1;&#x6D41;&#x91CF;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x901A;&#x8FC7; <code>kubectl describe ingress</code> &#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF1A;</p>
<pre class="language-"><code>Rules:
  Host              Path  Backends
  ----              ----  --------
  hello-world.info  
                    /web1   web1:8080 (192.168.56.1:80,192.168.56.2:80,192.168.56.63:80)
                    /web2   web2:9090 (192.168.56.3:80,192.168.56.4:80,192.168.56.5:80)
</code></pre><p>&#x5F53;&#x7528;&#x6237;&#x8BBF;&#x95EE; <code>hello-world.info/web1</code> &#x65F6;&#xFF0C;Ingress &#x5E76;&#x4E0D;&#x4F1A;&#x5C06;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x7ED9; Service web1&#xFF0C;&#x800C;&#x662F;&#x901A;&#x8FC7; Service web1 &#x9009;&#x62E9;&#x4E00;&#x4E2A; Pod&#xFF0C;&#x8FD9;&#x4E2A; Pod &#x5217;&#x8868;&#x548C; Pod &#x7684; IP &#x5217;&#x8868;&#xFF0C;&#x662F; Endpoint &#x63D0;&#x4F9B;&#x7684;&#x3002;</p>
<p>&#x5F53;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x65F6; <code>hello-world.info</code> &#x65F6;&#xFF0C;&#x4F1A;&#x9996;&#x5148;&#x8FDB;&#x884C; DNS &#x67E5;&#x627E;&#xFF0C;&#x83B7;&#x53D6;&#x5B9E;&#x9645;&#x8BF7;&#x6C42;&#x7684; IP&#xFF0C;&#x7136;&#x540E;&#x8BF7;&#x6C42;&#x4F1A;&#x53D1;&#x9001;&#x5230; ingress-nginx &#x8FD9;&#x4E2A; Ingress &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x63A5;&#x7740; Ingress &#x63A7;&#x5236;&#x5668;&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x7684; HOST/URL &#x786E;&#x5B9A;&#x8981;&#x8BBF;&#x95EE;&#x54EA;&#x4E2A; Service&#xFF0C;&#x6700;&#x540E;&#x6839;&#x636E; Service &#x5173;&#x8054;&#x7684; Endpoint &#x5BF9;&#x8C61;&#xFF0C;&#x67E5;&#x770B; Pod &#x7684; IP&#xFF0C;&#x6700;&#x540E;&#xFF0C;Ingress &#x63A7;&#x5236;&#x5668;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x7ED9;&#x5176;&#x4E2D;&#x4E00;&#x4E2A; Pod&#x3002;</p>
<h3 id="ingress-&#x7ED3;&#x6784;"><a name="ingress-&#x7ED3;&#x6784;" class="anchor-navigation-ex-anchor" href="#ingress-&#x7ED3;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>Ingress &#x7ED3;&#x6784;</h3>
<p>Ingress &#x7531; Ingress Controller&#x3001;Ingress API &#x4E24;&#x90E8;&#x5206;&#x7EC4;&#x6210;&#xFF0C;&#x4E3A;&#x4E86;&#x8BA9; Ingress &#x8D44;&#x6E90;&#x5DE5;&#x4F5C;&#xFF0C;&#x96C6;&#x7FA4;&#x5FC5;&#x987B;&#x6709;&#x4E00;&#x4E2A;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684; Ingress &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x5728;&#x524D;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E86; ingress-nginx &#x63A7;&#x5236;&#x5668;&#x3002; Ingress &#x63A7;&#x5236;&#x5668; &#x8D1F;&#x8D23;&#x6EE1;&#x8DB3; Ingress &#x4E2D;&#x6240;&#x8BBE;&#x7F6E;&#x7684;&#x89C4;&#x5219;&#xFF0C;&#x5373;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#xFF0C;&#x4F8B;&#x5982; nginx&#xFF0C;&#x6211;&#x4EEC;&#x8131;&#x79BB; Kubernetes&#xFF0C;&#x5355;&#x72EC;&#x90E8;&#x7F72;&#x4F7F;&#x7528; nginx &#x4E5F;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x8FD9;&#x4E2A;&#x9700;&#x6C42;&#x3002;</p>
<p>&#x7531;&#x4E8E; CKAD &#x8BA4;&#x8BC1;&#x4E2D;&#xFF0C;&#x53EA;&#x8981;&#x6C42;&#x638C;&#x63E1; Ingress &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x800C;&#x4E14;&#x5F88;&#x591A;&#x4E66;&#x4E2D;&#x90FD;&#x4E0D;&#x4F1A;&#x6DF1;&#x5165; ingress&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x91CC;&#x7B14;&#x8005;&#x4E0D;&#x518D;&#x6DF1;&#x5165;&#x8BB2;&#x89E3;&#xFF0C;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x53C2;&#x8003;&#x5B98;&#x65B9;&#x6587;&#x6863;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5176;&#x5B83; ingress &#x63A7;&#x5236;&#x5668;&#xFF0C;&#x4F8B;&#x5982;&#x7ECF;&#x5E38;&#x63D0;&#x53CA;&#x5230;&#x7684; Istio&#xFF0C;&#x8BE6;&#x7EC6;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x5B98;&#x65B9;&#x5B8C;&#x6574;&#x540D;&#x5355;&#xFF1A;</p>
<p><a href="https://kubernetes.io/zh/docs/concepts/services-networking/ingress-controllers/#%E5%85%B6%E4%BB%96%E6%8E%A7%E5%88%B6%E5%99%A8" target="_blank">https://kubernetes.io/zh/docs/concepts/services-networking/ingress-controllers/#&#x5176;&#x4ED6;&#x63A7;&#x5236;&#x5668;</a></p>
<p><a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/" target="_blank">https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/</a></p>
<h3 id="ingress-&#x7C7B;&#x578B;"><a name="ingress-&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#ingress-&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>Ingress &#x7C7B;&#x578B;</h3>
<p>&#x5728;&#x6DF1;&#x5165; Ingress &#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x4E86;&#x89E3;&#x4E00;&#x4E0B; Ingress &#x7684;&#x7C7B;&#x578B;/&#x67B6;&#x6784;&#xFF0C;&#x8FD9;&#x4E5F;&#x79F0;&#x4E3A;&#x8C03;&#x5EA6;&#x65B9;&#x5F0F;&#xFF0C;&#x8FD9;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x4E86;&#x89E3;&#x5982;&#x4F55;&#x8BBE;&#x8BA1; Ingress&#x3002;</p>
<h4 id="&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;"><a name="&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;" class="anchor-navigation-ex-anchor" href="#&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;</h4>
<p>&#x5728; Ingress &#x4E2D;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x7684; URL &#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x533A;&#x914D;&#x7684; Service &#x53EF;&#x7528;&#x65F6;&#xFF0C;&#x4F1A;&#x8FD4;&#x56DE; 404&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;(Service)&#xFF0C;&#x5F53;&#x8BF7;&#x6C42;&#x7684; URL &#x4E0D;&#x5B58;&#x5728;&#x65F6;&#x5BF9;&#x5E94;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#x65F6;&#xFF0C;&#x6B64;&#x8BF7;&#x6C42;&#x4F1A;&#x88AB;&#x8DEF;&#x7531;&#x5230;&#x9ED8;&#x8BA4;&#x7684;&#x540E;&#x7AEF;(Service)&#x4E2D;&#x3002;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">defaultBackend</span><span class="token punctuation">:</span>
    <span class="token key atrule">resource</span><span class="token punctuation">:</span>
      <span class="token key atrule">apiGroup</span><span class="token punctuation">:</span> k8s.example.com
      <span class="token key atrule">kind</span><span class="token punctuation">:</span> StorageBucket
      <span class="token key atrule">name</span><span class="token punctuation">:</span> static<span class="token punctuation">-</span>assets
  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">http</span><span class="token punctuation">:</span>
        <span class="token key atrule">paths</span><span class="token punctuation">:</span>
          <span class="token punctuation">-</span> <span class="token key atrule">path</span><span class="token punctuation">:</span> /icons
            <span class="token key atrule">pathType</span><span class="token punctuation">:</span> ImplementationSpecific
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
            <span class="token punctuation">...</span> <span class="token punctuation">...</span>
</code></pre>
<h4 id="&#x5355;&#x4E2A;-service"><a name="&#x5355;&#x4E2A;-service" class="anchor-navigation-ex-anchor" href="#&#x5355;&#x4E2A;-service"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5355;&#x4E2A; Service</h4>
<p>&#x8FD9;&#x79CD; Ingress &#x53EA;&#x6709;&#x4E00;&#x4E2A; &#x540E;&#x7AEF;&#xFF0C;&#x5373;&#x4E00;&#x4E2A; Service &#xFF0C;Ingress &#x4F1A;&#x5C06;&#x6240;&#x6709;&#x6D41;&#x91CF;&#x90FD;&#x53D1;&#x9001;&#x5230;&#x540C;&#x4E00; Service &#x7684;&#x7B80;&#x5355; Ingress&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x5176;&#x53EA;&#x9700;&#x8981;&#x4E00;&#x4E2A; Service&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528; <code>DefaultBackend</code> &#x6307;&#x5B9A;&#x4E00;&#x4E2A; Service &#x5373;&#x53EF;&#xFF0C;&#x5982; <code>&#x5FEB;&#x901F;&#x5B9E;&#x8DF5;</code> &#x4E00;&#x5C0F;&#x8282;&#x4E2D;&#x7684; Ingress &#x6A21;&#x677F;&#x3002;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">defaultBackend</span><span class="token punctuation">:</span>
    <span class="token key atrule">service</span><span class="token punctuation">:</span>
      <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
      <span class="token key atrule">port</span><span class="token punctuation">:</span>
        <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">8080</span>
</code></pre>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">defaultBackend</span><span class="token punctuation">:</span>
    <span class="token key atrule">resource</span><span class="token punctuation">:</span>
      <span class="token key atrule">apiGroup</span><span class="token punctuation">:</span> my666.com
      <span class="token key atrule">kind</span><span class="token punctuation">:</span> StorageBucket
      <span class="token key atrule">name</span><span class="token punctuation">:</span> static<span class="token punctuation">-</span>assets
</code></pre>
<p><img src="images/&#x5355;&#x4E2A;Service.png" alt="&#x5355;&#x4E2A;Service"></p>
<h4 id="&#x7B80;&#x5355;&#x6247;&#x51FA;"><a name="&#x7B80;&#x5355;&#x6247;&#x51FA;" class="anchor-navigation-ex-anchor" href="#&#x7B80;&#x5355;&#x6247;&#x51FA;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x7B80;&#x5355;&#x6247;&#x51FA;</h4>
<p>&#x4E00;&#x4E2A;&#x6247;&#x51FA;&#x914D;&#x7F6E;(&#x5E26;<code>rule</code>)&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x7684; HTTP URL&#xFF0C; &#x5C06;&#x6765;&#x81EA;&#x540C;&#x4E00; IP &#x5730;&#x5740;&#x7684;&#x6D41;&#x91CF;&#x8DEF;&#x7531;&#x5230;&#x591A;&#x4E2A; Service&#x4E2D;&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x4E5F;&#x79F0;&#x4E3A; URL &#x6620;&#x5C04;&#xFF0C;&#x5373;&#x6211;&#x4EEC;&#x5728;&#x524D;&#x9762;&#x521B;&#x5EFA;&#x7684;&#x591A; Service &#x3002;</p>
<p><img src="images/&#x7B80;&#x5355;&#x6247;&#x51FA;.png" alt="&#x7B80;&#x5355;&#x6247;&#x51FA;"></p>
<blockquote>
<p>&#x5982;&#x679C;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x7684; URL&#xFF0C;&#x6CA1;&#x6709; <code>hosts</code> &#x6216; <code>paths</code> &#x4E0E; Ingress &#x5BF9;&#x8C61;&#x4E2D;&#x7684; HTTP &#x8BF7;&#x6C42;&#x5339;&#x914D;&#xFF0C;&#x5219;&#x6D41;&#x91CF;&#x5C06;&#x8DEF;&#x7531;&#x5230;&#x9ED8;&#x8BA4;&#x540E;&#x7AEF;&#x3002;</p>
</blockquote>
<h4 id="&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;"><a name="&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;</h4>
<p>&#x5373;&#x57DF;&#x540D;&#x6A21;&#x5F0F;&#xFF0C;Ingrss &#x6839;&#x636E;&#x57DF;&#x540D;&#x7684;&#x4E0D;&#x540C;&#xFF0C;&#x5C06;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x5230;&#x4E0D;&#x540C;&#x7684; Pod &#x4E2D;&#xFF0C;&#x4E00;&#x822C;&#x4F1A;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x5B50;&#x57DF;&#x540D;&#x8BBF;&#x95EE;&#x4E0D;&#x540C;&#x7684; Service&#x3002;</p>
<p><img src="images/&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;.png" alt="&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x7684;&#x865A;&#x62DF;&#x6258;&#x7BA1;"></p>
<h4 id="tls"><a name="tls" class="anchor-navigation-ex-anchor" href="#tls"><i class="fa fa-link" aria-hidden="true"></i></a>TLS</h4>
<p>Ingress &#x4E5F;&#x652F;&#x6301; HTTPS&#xFF0C;&#x901A;&#x8FC7; SSL &#x8BC1;&#x4E66;&#x4E3A; HTTPS &#x63D0;&#x4F9B;&#x5B89;&#x5168;&#x4FDD;&#x969C;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x4E91;&#x670D;&#x52A1;&#x5546;&#x7684;&#x57DF;&#x540D;&#x5904;&#xFF0C;&#x4E3A;&#x57DF;&#x540D;&#x5206;&#x914D; SSL &#x8BC1;&#x4E66;&#x540E;&#xFF0C;&#x83B7;&#x53D6; <code>.key</code>&#x3001;<code>.crt</code> &#x4E24;&#x4E2A;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#xFF0C; TLS Secret &#x5FC5;&#x987B;&#x5305;&#x542B;&#x540D;&#x4E3A; <code>tls.crt</code> &#x548C; <code>tls.key</code> &#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x5C06;&#x8BC1;&#x4E66;&#x4FDD;&#x5B58;&#x5230; Kubernetes &#x7684; Secret &#x5BF9;&#x8C61;&#x4E2D;&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl create secret tls <span class="token punctuation">{</span>secret&#x540D;&#x79F0;<span class="token punctuation">}</span> --key <span class="token punctuation">{</span>&#x8BC1;&#x4E66;&#x540D;&#x79F0;<span class="token punctuation">}</span>.key --cert <span class="token punctuation">{</span>&#x8BC1;&#x4E66;&#x540D;&#x79F0;<span class="token punctuation">}</span>.crt
</code></pre>
<p>&#x7136;&#x540E;&#x5728; Ingress &#x5BF9;&#x8C61;&#x7684; YAML &#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x52A0;&#x4E0A; TLS &#x8BC1;&#x4E66;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">tls</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">hosts</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> mywebsite.com
    <span class="token key atrule">secretName</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>secret&#x540D;&#x79F0;<span class="token punctuation">}</span>
  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">http</span><span class="token punctuation">:</span>
  <span class="token punctuation">...</span> <span class="token punctuation">...</span>
</code></pre>
<blockquote>
<p>TLS &#x8FDE;&#x63A5;&#x7EC8;&#x6B62;&#x4E8E; Ingress &#x7AEF;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x8DDF; Ingress &#x4E4B;&#x95F4;&#x901A;&#x8FC7; HTTPS &#x4F20;&#x8F93;&#xFF0C;&#x7136;&#x540E; Ingress &#x5C06;&#x6D41;&#x91CF;&#x8F6C;&#x53D1;&#x5230; Pod &#x4E2D;&#xFF0C;&#x6B64;&#x65F6;&#x4EE5; HTTP &#x4F20;&#x8F93;&#xFF0C;Pod &#x4E2D;&#x7684; Web &#x5E94;&#x7528;&#x4E0D;&#x9700;&#x8981;&#x652F;&#x6301; HTTPS&#x3002;</p>
</blockquote>
<p>&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4E0D;&#x4F7F;&#x7528; secret&#xFF0C;TLS &#x8BC1;&#x4E66;&#x76F4;&#x63A5;&#x9644;&#x52A0;&#x5230; Ingress YAML &#x4E2D;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Secret
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> testsecret<span class="token punctuation">-</span>tls
  <span class="token key atrule">namespace</span><span class="token punctuation">:</span> default
<span class="token key atrule">data</span><span class="token punctuation">:</span>
  <span class="token key atrule">tls.crt</span><span class="token punctuation">:</span> base64 &#x7F16;&#x7801;&#x7684; cert
  <span class="token key atrule">tls.key</span><span class="token punctuation">:</span> base64 &#x7F16;&#x7801;&#x7684; key
<span class="token key atrule">type</span><span class="token punctuation">:</span> kubernetes.io/tls
</code></pre>
<blockquote>
<p>secret &#x7684;&#x77E5;&#x8BC6;&#x5728; 5.2 &#x7AE0;&#x4E2D;&#x8BB2;&#x89E3;&#x3002;</p>
</blockquote>
<p>&#x7B14;&#x8005;&#x5B9E;&#x9A8C;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<p>&#x7533;&#x8BF7;&#x57DF;&#x540D;&#x8BC1;&#x4E66;&#xFF1A;</p>
<p><img src="images/tls1.png" alt="tls1"></p>
<p><img src="images/tls2.jpg" alt="tls2"></p>
<p>&#x5C06;&#x8BC1;&#x4E66;&#x4E0A;&#x4F20;&#x5230;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x521B;&#x5EFA; secret&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl create secret tls tls-secret --cert<span class="token operator">=</span>1_k1.whuanle.cn_bundle.crt --key<span class="token operator">=</span>2_k1.whuanle.cn.key
</code></pre>
<p>&#x91CD;&#x65B0;&#x521B;&#x5EFA; Ingress&#xFF0C;&#x5E76;&#x914D;&#x7F6E; TLS&#xFF0C;Ingress &#x7684; YAML &#x6587;&#x4EF6;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> networking.k8s.io/v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Ingress
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> test<span class="token punctuation">-</span>ingress
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">ingressClassName</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">tls</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">hosts</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> k1.whuanle.cn
    <span class="token key atrule">secretName</span><span class="token punctuation">:</span> tls<span class="token punctuation">-</span>secret
  <span class="token key atrule">rules</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">host</span><span class="token punctuation">:</span> k1.whuanle.cn
      <span class="token key atrule">http</span><span class="token punctuation">:</span>
        <span class="token key atrule">paths</span><span class="token punctuation">:</span>
          <span class="token punctuation">-</span> <span class="token key atrule">path</span><span class="token punctuation">:</span> /web1
            <span class="token key atrule">pathType</span><span class="token punctuation">:</span> Prefix
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web1
                <span class="token key atrule">port</span><span class="token punctuation">:</span>
                  <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">8080</span>
          <span class="token punctuation">-</span> <span class="token key atrule">path</span><span class="token punctuation">:</span> /web2
            <span class="token key atrule">pathType</span><span class="token punctuation">:</span> Prefix
            <span class="token key atrule">backend</span><span class="token punctuation">:</span>
              <span class="token key atrule">service</span><span class="token punctuation">:</span>
                <span class="token key atrule">name</span><span class="token punctuation">:</span> web2
                <span class="token key atrule">port</span><span class="token punctuation">:</span>
                  <span class="token key atrule">number</span><span class="token punctuation">:</span> <span class="token number">9090</span>
</code></pre>
<p>&#x901A;&#x8FC7; https:// &#x8BBF;&#x95EE;&#x57DF;&#x540D;&#xFF1A;</p>
<p><img src="images/tls3.jpg" alt="tls3"></p>
<blockquote>
<p><strong>[Info] &#x63D0;&#x793A;</strong></p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x7531;&#x4E8E;&#x6CA1;&#x6709;&#x516C;&#x7F51;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#x505A;&#x5165;&#x53E3;&#xFF0C;&#x5176;&#x65B9;&#x5F0F;&#x662F; Service&#xFF0C;&#x6240;&#x4EE5; 80&#xFF0C;443 &#x7AEF;&#x53E3;&#x7528;&#x4E0D;&#x4E86;&#xFF0C;&#x7B14;&#x8005;&#x7684; Service &#x4F7F;&#x7528;</p>
<p><code>80:32587/TCP,443:31520/TCP</code> &#x4EE3;&#x66FF;&#x8BBF;&#x95EE;&#x3002;&#x5F53;&#x7136;&#xFF0C;Service &#x7684;&#x7AEF;&#x53E3;&#x662F;&#x53EF;&#x4EE5;&#x624B;&#x52A8;&#x4FEE;&#x6539;&#x7684;&#xFF0C;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x8303;&#x56F4;&#x662F; 31000-32000&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#xFF0C;&#x4F7F;&#x5176;&#x7ED1;&#x5B9A; 80 &#x548C; 443 &#x7AEF;&#x53E3;&#x3002;</p>
</blockquote>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x75F4;&#x8005;&#x5DE5;&#x826F; 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x6863;&#x6700;&#x540E;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2021-11-17 07:19:36
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2.endpoint.html" class="navigation navigation-prev " aria-label="Previous page: 4.2 Endpoint">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.discovery.html" class="navigation navigation-next " aria-label="Next page: 4.4 服务发现">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4.3 ingress","level":"1.5.4","depth":2,"next":{"title":"4.4 服务发现","level":"1.5.5","depth":2,"path":"4.network/4.discovery.md","ref":"4.network/4.discovery.md","articles":[]},"previous":{"title":"4.2 Endpoint","level":"1.5.3","depth":2,"path":"4.network/2.endpoint.md","ref":"4.network/2.endpoint.md","articles":[]},"dir":"ltr"},"config":{"plugins":["tbfed-pagefooter","anchor-navigation-ex","mermaid-gb3","insert-logo","chapter-fold","advanced-emoji","github","splitter","alerts","popup","prism","-highlight","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 痴者工良 2021","modify_label":"文档最后更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"prism":{"lang":{"flow":"typescript","shell":"bash"},"ignore":["mermaid","eval-js"],"css":["prismjs/themes/prism.css"],"js":["prismjs/prism.js","prismjs/components.js","prismjs/components/prism-go.min.js","prismjs/components/prism-yaml.min.js","prismjs/components/prism-bash.min.js","prismjs/components/prism-shell-session.min.js"]},"github":{"url":"https://github.com/whuanle/kubernetes"},"livereload":{},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"alerts":{},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"/images/logo.jpg"}},"theme":"default","author":"痴者工良","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Kubernetes - 痴者工良","language":"zh-hans","links":{"sidebar":{"痴者工良的博客":"https://www.whuanle.cn"}},"gitbook":"*","description":"这是一本关于 Kubernetes 的书，作者 痴者工良"},"file":{"path":"4.network/3.ingress.md","mtime":"2021-11-16T23:19:36.250Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-16T23:21:22.294Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

